User defined functions
These are cut-and-paste functions that you can use in your addons, submitted by WoWWiki contributors. See also UI Snippets. Additional snippets and useful ideas: → AddOn defined functions → User defined macros → User defined modules Reference The following functions aim at extending the information WoW API provides; some are provided by specialized addons rather than being copy/pastable. API : (type,...) - Returns true if all the additional parameters are of the type specified. Arguments & Returns : (myTable, "name", ...) - remember list of arguments to use for a callback : (myTable, "name", ...) - retreive stored list of arguments, plus optional extras : (order, functionCall) - Get the return values from functionCall in any order you want. Color Functions : (perc, R1, G1, B1, R2, G2, B2...) - Converts a percent value into a gradient from 2 or more RGB values : ("string") - Converts a hex color string to RGB values (0-255) : ("string") - Converts a hex color string to RGB values (0.0-1.0) : (red, green, blue) - Converts a RGB value (0-255) into a hex string : (red, green, blue) - Converts a RGB value (0.0-1.0) into a hex string Cursor Functions : () - Return the exact position the cursor is at based on scale. Event Functions : - Add a message to the chat frame when you gain or spend money. Frame Functions : (frame) - Find which quadrant of the screen a frame lies in. : (frame) - Returns SetPoint args for a frame, anchor is relative to nearest corner of screen. : (...) - Register n''' number of events at once. : (...) - Unregister '''n number of events at once. : (...) - Simple function to embed in a frame to set many atributes at once. : (event) - Tell all the frames listening for event to stop listening for it. : (uid, dropdown, index, title, usable, onClick hint) - Adds a new button to a drop down (right-click menu) Guild Functions : (name, searchOffline) - finds the 'guild' player index for a player name, for other guild functions. Item Functions : (link) - Equips the first matching item found in the player's bags. Localization Tables : - Table of localized classes Map Functions : () - Returns the player's current facing bearing based on minimap arrow Metatables : - A special table that calculates values as needed and saves them into itself Number Functions : (input, n) - Round input to n places. : (number, n) - Truncate a number to n decimal places. Slash Function : - Get an existing slash command function for hooking. : - Passes a slash command to the chatframe : (name, func, ...) String Functions : (string length [, endChars]) - Splits string into groups of 'length' each ending with 'endChars' (identical to PHP ChunkSplit). : (haystack, needle) - Return how many times needle is contained in haystack. : ("string") - Split words on space boundary, return table : ("string") - Displays a custom message to the default chat frame, for the user to see (time, code and size saver). : (tabCaptures, ...) - Wrapper for strfind() that returns captures in a table. can be used in if() clauses! : ("string") - Create a fair-quality 32-bit hash of a string : ("string", start length) - Imp strsub. Returns a string from start of length (identical to PHP substr). Table Functions : (t) - Erase all values from a table : (tab, valBefore, val) - Insert one value before another (without knowing its index) : (tab, val) - Remove a value (without knowing its index) : (tab) - Count table members (works on non-integer-indexed tables) : (tabTo, tabFrom) - Recursively copy contents of one table to another Time Functions : () - Get server time including seconds and milliseconds : (delay,function param [,param [,...]]) - runs a function (with paramenters) after specified amount of time before : () - Converts seconds to days/hours/minutes/seconds See also * Category:HOWTOs - must have cut-and-pasteable code snippets User defined functions